/**
 * 获取指定cookie的值
 * @param cname
 * @returns
 */
function getCookie(cname) {
	var name = cname + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i].trim();
		if (c.indexOf(name) == 0)
			return unescape(c.substring(name.length, c.length));
	}
	return "";
}

/**
 * 设置cookie
 * @param cname cookie的名称
 * @param cvalue cookie的值
 * @param exdays 有效期，单位d
 * @returns
 */
function setCookie(cname, cvalue, exdays) {
	var d = new Date();
	d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
	var expires = "expires=" + d.toGMTString();
	document.cookie = cname + "=" + escape(cvalue) + "; " + expires;
}

/**
 * ajax异步请求
 * @param options 请求参数
 * @returns
 */
function ajax(options){
	var xmlHttp=new XMLHttpRequest();
	xmlHttp.open(options.method, options.url, true);
	xmlHttp.onreadystatechange=function()
	{
	    if (xmlHttp.readyState==4 && xmlHttp.status==200)
	    {
	        options.onsuccess(xmlHttp.responseText);
	    }
	}
	if(options.method=="POST"){
		xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlHttp.send(options.data);
	}else{
		xmlHttp.send();
	}
}

/*
 * 判断一个字符串是否为空串
 */
function isEmptyString(string) {
	var emptyIndex = 0;
	//获取左边空串的长度
	while (string.indexOf(" ", emptyIndex) != -1) {
		emptyIndex++;
	}
	if (emptyIndex == string.length) {
		return true;
	}
	return false;
};

/**
 * 获取指定元素的绝对坐标
 * @param element
 * @returns object(left, top)
 */
function getAbsolutePosition(element){
	var actualLeft = element.offsetLeft;
	var actualTop = element.offsetTop;
	var current = element.offsetParent;
	while (current !== null){
		actualLeft += current.offsetLeft;
		actualTop += current.offsetTop;
		current = current.offsetParent;
　　	}
	var obj = {};
	obj.left = actualLeft;
	obj.top = actualTop;
	
	return obj;
};
